﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace epk23.PartIIProject
{
    interface UIAction
    {
        void undo();
        void redo();
    }
    class MoveNodeAction : UIAction
    {
        MachineGraph graph;
        ConcreteNode node;
        Point startPoint;
        Point endPoint;

        public MoveNodeAction(ConcreteNode node, Point startPoint, Point endPoint, MachineGraph graph)
        {
            this.graph = graph;
            this.node = node;
            this.startPoint = startPoint;
            this.endPoint = endPoint;
        }

        public void undo()
        {
            graph.moveNode(graph.lookupNode(node.getRule().ruleNumber), startPoint.X, startPoint.Y);

        }

        public void redo()
        {
            graph.moveNode(graph.lookupNode(node.getRule().ruleNumber), endPoint.X, endPoint.Y);
        }
    }

    class ChangeGraphAction : UIAction
    {
        MachineGraph graph;
        GraphState oldState;
        public GraphState newState { get; set; }

        public ChangeGraphAction(MachineGraph graph, GraphState oldState, GraphState newState)
        {
            this.graph = graph;
            this.oldState = oldState;
            this.newState = newState;
        }

        public void undo()
        {
            graph.loadState(oldState);
        }

        public void redo()
        {
            graph.loadState(newState);
        }
    }

    class SetStartNodeAction : UIAction
    {
        private RuleNode oldStartNode;
        private RuleNode newStartNode;
        private MachineGraph graph;

        public SetStartNodeAction(RuleNode oldStartNode, RuleNode newStartNode, MachineGraph graph)
        {
            this.oldStartNode = oldStartNode;
            this.newStartNode = newStartNode;
            this.graph = graph;
        }

        public void undo()
        {
            graph.setStartNode(oldStartNode);
        }

        public void redo()
        {
            graph.setStartNode(newStartNode);
        }
    }
}
